const express = require("express");
const chalk = require("react-dev-utils/chalk");
const app = express();
const port = 3001;
app.use((req, res, next) => {
    //设置请求头
    res.set({
        'Access-Control-Allow-Credentials': true,
        'Access-Control-Max-Age': 1728000,
        'Access-Control-Allow-Origin': req.headers.origin || '*',
        'Access-Control-Allow-Headers': 'X-Requested-With,Content-Type',
        'Access-Control-Allow-Methods': 'PUT,POST,GET,DELETE,OPTIONS',
        'Content-Type': 'application/json; charset=utf-8'
    })
    req.method === 'OPTIONS' ? res.status(204).end() : next()
});
const routers = [
    require('./controllers/test')
]
for(let route of routers) {
    for(let item of route) {
        app[item.method]('/api/v1'+item.path, item.callback);
    }
}
app.get('/', function(req, res) {
    res.send('hello world'); 
});
 
app.listen(port, () => {
    console.log(chalk.yellow(`mock start success!listen port ${port}!`));
});